package com.meixiang.adapter.service;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.meixiang.R;
import com.meixiang.entity.services.Index;
import com.meixiang.global.Config;
import com.meixiang.recyclerview.RecyclerAdapter;
import com.meixiang.tool.Tool;
import com.meixiang.util.DensityUtil;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * 美服务-预约-项目 适配器
 */
public class ProjectAdapter extends RecyclerAdapter<ProjectAdapter.ViewHolder> {
    private Fragment fragment;
    public List<Index.ListBean> data=new ArrayList<>();
    private Context mContext;
    public ProjectAdapter(Fragment fragment){
        this.fragment=fragment;
    }
    public void addData(List<Index.ListBean> data){
        this.data.addAll(data);
        notifyDataSetChanged();
    }
    public void clearData(){
        data.clear();
        notifyDataSetChanged();
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        mContext=parent.getContext();
        View view = LayoutInflater.from(mContext).inflate(R.layout.list_item_project, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {
        int width= Tool.getWindowWith(mContext)- DensityUtil.dip2px(mContext,20);
        int height= (int) (width/ Config.imgScale);//宽高比例 710/346
        holder.ivBackground.setLayoutParams(new FrameLayout.LayoutParams(width,height));
        //GlideHelper.showRoundImage(mContext, data.get(position).getGoodsImage(), R.drawable.image_default_gray_bg, DensityUtil.dip2px(mContext, 2), holder.ivBackground);
        Glide.with(fragment)
                .load(data.get(position).getGoodsImage())
                .placeholder(R.drawable.image_default_gray_bg)
                .error(R.drawable.image_default_gray_bg)
                .override(width, height)
                .into(holder.ivBackground);

        holder.tvTitle.setText(data.get(position).getGoodsName());
        holder.tvMoney.setText("¥"+data.get(position).getGoodsStorePrice());
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

   static class ViewHolder extends RecyclerView.ViewHolder{
        @Bind(R.id.iv_background)
        ImageView ivBackground;
        @Bind(R.id.tv_title)
        TextView tvTitle;
        @Bind(R.id.tv_money)
        TextView tvMoney;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
